home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr11
/
powerb5.zip
/
P5DOS008.TIP
< prev
next >
Wrap
Text File
|
1993-06-01
|
5KB
|
109 lines
Many programs, including word processors and spreadsheets,
allow you to temporarily shell out to DOS. But if you are in
one of these temporary DOS sessions when you invoke a batch
file -- especially one of the more complex ones featured in
Star-Dot-Star --you may find that the batch fails for lack
of environment space.
Here's why. When you shell out of a typical application
program, DOS re-creates a new environment space, with copies
of all the existing environment variables, in whatever
unused memory it finds. But since it anticipates a potential
memory shortage, DOS makes the new environment space just
big enough to hold all the existing variables; it doesn't
leave any room for new ones! Thus, when a batch file
attempts to create a new environment variable, it gets an
'Out of environment space' error message. The batch
continues, but produces incorrect (or even dangerous)
results because it can't save information in the
environment. One solution to this problem is to create a
"dummy" environment variable for reserving space. For
instance, if you add the line SET RESERVE=XX.....XXX (where
there are 120 X's on the line) to your AUTOEXEC.BAT file,
another batch file can reclaim the room in its own
environment with the command SET RESERVE= (where nothing
follows the equal sign). The problem with this approach is
that everyone who might use the batch file must have the
command in his or her AUTOEXEC.BAT if the other batch files
are to access the extra room.
Here's another solution: If you know a batch file will
require lots of environment space, but you don't know how
much will be available, you can design the batch file to
temporarily enlarge its own environment. BIGENV.BAT provides
an example of how you can do this.
BIGENV.BAT works by calling itself. When launched,
BIGENV.BAT checks if its first parameter contains ?Do_It?.
If not, BIGENV runs COMMAND.COM with two switches: /E:1024,
to create a 1K environment, and /C, to run the string that
follows as a command. That string runs the batch file again,
this time passing it the ?Do_It? parameter. Because of the
passed parameter, BIGENV skips to the Do_It label when it
runs inside of itself. A SHIFT command deletes the special
argument and shifts the others to the left. The batch can
now continue, knowing that it has enough room to work. When
the batch is finished, the recursion "unwinds" and the extra
COMMAND.COM, with its 1K environment space, is unloaded.
Ron Lewis
Huntsville, Alabama
Editor's Note: Each of these approaches is useful under
different circumstances. The "reserve" variable is ideal
when you need a small amount of space (the most you can
reclaim is 123 bytes), and you can edit AUTOEXEC.BAT and
your other batch files to use it. Unlike the second
technique, this one guarantees that you'll get a specific
amount of free environment space, and it doesn't take up
extra RAM by reinvoking COMMAND.COM. The downside of this
technique: if your batch file CALLs another that also uses
the same "reserve" variable, the two will compete for the
same RAM and one of them won't work.
The second technique is better when you need more room. It's
also easier to set up, because all you need to do is place
the appropriate commands at the beginning and end of an
existing batch file with heavy environmental needs. However,
this method has two drawbacks. First, because it tries to
load another copy of the transient portion of COMMAND.COM
(which can be as big as 17K), it wastes conventional RAM.
Second, the amount of free environment space provided by
this technique isn't guaranteed. If your system already has
1009 bytes of environment variables, /E:1024 will provide no
more space than you had before. (DOS always rounds the size
of the environment up to a multiple of 16 bytes.) For this
reason, I recommend this technique primarily for situations
in which you can closely estimate the amount of environment
space that's already been used.
As you may have noticed, this volume of PowerBase *.* has
several tips with batch files that call themselves; each of
these files uses a similar technique to solve a very
different problem. Just goes to show what a little bit of
creativity can do.
BIGENV.BAT
---- BEGIN LISTING ----
@ECHO OFF
IF "%1" == "?Do_It?" GOTO Do_It
COMMAND.COM /E:1024 /C BIGENV ?Do_It? %1 %2 %3 %4 %5 %6 %7
%8 %9
GOTO Exit
:Do_It
SHIFT
REM Place call to regular batch file command on next line
:Exit
---- END LISTING ----
Title: Ways to Save the Environment
Category: DOS
Issue Date: August, 1992
Editor: Brett Glass
Supplementary Files: None
Filename: P5DOS008.TIP